<template>
	<view>
		<!-- 搜索区域 -->
		<view class="search-box" @click="searchbox">
			<my-search></my-search>
		</view>
		<!-- 轮播图区域 -->
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
			<swiper-item v-for="(item,i) in SwiperList" :key="i">
				<navigator class="swiper-item" :url="'/subpkg/goods_detail/goods_detail?goods_id='+item.goods_id">
					<img :src="item.image_src">
				</navigator>
			</swiper-item>
		</swiper>

		<!-- 分类导航区域 -->
		<view class="nav-list">
			<view class="nav-item" v-for="(item,i) in NavList" :key="i" @click="NavClickHandler(item)">
				<img :src="item.image_src" class="nav-img">
			</view>
		</view>

		<!-- 楼层区域 -->
		<!-- 楼层的容器 -->
		<view class="floor-list">
			<!-- 每一个楼层的item项 -->
			<view class="floor-item" v-for="(item,i) in FloorList" :key="i">
				<!-- 每一个楼层的title项 -->
				<img :src="item.floor_title.image_src" class="floor-title">
				<!-- 楼层的图片区域 -->
				<view class="img-box">
					<!-- 左侧大图片盒子 -->
					<navigator class="left-img-box" :url="item.product_list[0].url">
						<img :src="item.product_list[0].image_src"
							:style="{width: item.product_list[0].image_width+'rpx'}" mode="widthFix">
					</navigator>
					<!-- 右侧四个小图片盒子 -->
					<view class="right-img-box">
						<navigator class="right-box-item" v-for="(item2,i) in item.product_list" :key="i" v-if="i!==0"
							:url="item2.url">
							<img :src="item2.image_src" :style="{width:item2.image_width+'rpx'}" mode="widthFix">
						</navigator>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import badgeMix from '../../mixins/tabbar-badge.js'
	export default {
		mixins: [badgeMix],
		data() {
			return {
				SwiperList: [], //轮播图列表
				NavList: [], //分类列表
				FloorList: [], //楼层列表
			};
		},
		onLoad() {
			this.getSwiperList(),
				this.getNavList(),
				this.getFloorList()
		},
		methods: {
			searchbox() {
				uni.navigateTo({
					url: '/subpkg/search/search'
				})
			},
			getSwiperList() {
				uni.request({
					url: 'https://api-hmugo-web.itheima.net/api/public/v1/home/swiperdata',
					method: 'GET',
					success: (res) => {
						if (res.data.meta.status !== 200) {
							return uni.$showMsg()
						}
						this.SwiperList = res.data.message
					},
				})
			},
			getNavList() {
				uni.request({
					url: 'https://api-hmugo-web.itheima.net/api/public/v1/home/catitems',
					method: 'GET',
					success: (res) => {
						if (res.data.meta.status !== 200) {
							return uni.$showMsg()
						}
						this.NavList = res.data.message
					},
				})
			},
			NavClickHandler(item) {
				if (item.name === '分类') {
					uni.switchTab({
						url: '/pages/cate/cate'
					})
				}
			},
			getFloorList() {
				uni.request({
					url: 'https://api-hmugo-web.itheima.net/api/public/v1/home/floordata',
					method: 'GET',
					success: (res) => {
						if (res.data.meta.status !== 200) {
							return uni.$showMsg()
						}
						res.data.message.forEach(floor => {
							floor.product_list.forEach(proc => {
								proc.url = '/subpkg/goods_list/goods_list?' + proc
									.navigator_url.split('?')[1]
							})
						})
						this.FloorList = res.data.message
					},
				})
			}
		}
	}
</script>

<style lang="scss">
	swiper {
		height: 330rpx;

		.swiper-item,
		image {
			width: 100%;
			height: 100%;
		}
	}

	.nav-list {
		display: flex;
		justify-content: space-around;
		margin: 15px 0;

		.nav-img {
			width: 128rpx;
			height: 140rpx;
		}
	}

	.floor-title {
		width: 100%;
		height: 60rpx;
	}

	.right-img-box {
		display: flex;
		justify-content: space-around;
		flex-wrap: wrap;
	}

	.img-box {
		display: flex;
		padding-left: 10rpx;
	}

	.search-box {
		z-index: 999;
		top: 0;
		position: sticky;
	}
</style>